using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class PatientRelativeMap : EntityTypeConfiguration<PatientRelative>
	{
		public PatientRelativeMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.NextOfKin)
				.HasMaxLength(50);
				
			this.Property(t => t.FirstName)
				.HasMaxLength(50);
				
			this.Property(t => t.LastName)
				.HasMaxLength(50);
				
			this.Property(t => t.PhoneNumber)
				.HasMaxLength(50);
				
			this.Property(t => t.MobilePhoneNumber)
				.HasMaxLength(50);
				
			this.Property(t => t.Email)
				.HasMaxLength(50);
				
			this.Property(t => t.Note)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("PatientRelatives");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.PatientId).HasColumnName("PatientId");
			this.Property(t => t.RelativeId).HasColumnName("RelativeId");
			this.Property(t => t.FamilyRelativeTypeId).HasColumnName("FamilyRelativeTypeId");
			this.Property(t => t.OthRelativeTypeId).HasColumnName("OthRelativeTypeId");
			this.Property(t => t.NextOfKin).HasColumnName("NextOfKin");
			this.Property(t => t.FirstName).HasColumnName("FirstName");
			this.Property(t => t.LastName).HasColumnName("LastName");
			this.Property(t => t.BirthDate).HasColumnName("BirthDate");
			this.Property(t => t.PhoneNumber).HasColumnName("PhoneNumber");
			this.Property(t => t.MobilePhoneNumber).HasColumnName("MobilePhoneNumber");
			this.Property(t => t.Email).HasColumnName("Email");
			this.Property(t => t.Note).HasColumnName("Note");

			// Relationships
			this.HasRequired(t => t.Patient)
				.WithMany(t => t.PatientRelatives)
				.HasForeignKey(d => d.PatientId);
				
			this.HasOptional(t => t.RefFamilyRelativeType)
				.WithMany(t => t.PatientRelatives)
				.HasForeignKey(d => d.FamilyRelativeTypeId);
				
			this.HasOptional(t => t.RefOthRelativeType)
				.WithMany(t => t.PatientRelatives)
				.HasForeignKey(d => d.OthRelativeTypeId);
				
		}
	}
}

